﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/MasterPage.master" AutoEventWireup="true" CodeFile="ManageProduction.aspx.cs" Inherits="Admin_ManageProduction" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <script type="text/javascript">
        $(function () {
            function getData() {
                var setting = $('#grid').datagrid("options");
                var result = DarkCRM.Production.GetPageing(parseInt(setting.pageSize), setting.pageNumber);
                //console.log(result);
                if (result.ErrorCode == 0)
                    return result.Value;
                else
                    alert(result.Name);
            }

            var lastIndex;
            $('#grid').datagrid({
                title: '管理产品',
                iconCls: 'icon-save',
                width: 900,
                height: 500,
                nowrap: false,
                striped: false,
                collapsible: false, //是否显示收放按钮
                pageSize: 10,
                pageList: [10, 20],
                datafun: getData,
                sortName: 'ID', //初始排序字段
                sortOrder: 'desc',            //初始排序
                idField: 'ID',
                queryParams: { pid: 1234 }, //附加参数
                showFooter: true,
                remoteSort: true, //通过服务端排序
                singleSelect: true,
                columns: [[
					{ field: "CreateDate", title: '创建时间', width: 150, formatter: function (value, rowData, rowIndex) { return dark.converDate(value); } },                    
					{ field: "Title", title: '标题', editor: "text", width: 220},					
                    { field: "control", title: '操作', width: 150, formatter: function (value, rowData, rowIndex) {
                        return "<a href=\"javascript:production.del('" + rowData.ID + "')\">删除</a> | <a href=\"javascript:production.edit('" + rowData.ID + "')\">修改</a>"
                    }
                    }
				]],
                pagination: true,
                rownumbers: true,
                onClickRow: function (rowIndex) {
                    if (lastIndex != rowIndex) {
                        //$('#grid').datagrid('endEdit', lastIndex);
                        //$('#grid').datagrid('beginEdit', rowIndex);
                    }
                    lastIndex = rowIndex;
                },
                onAfterEdit: function (rowIndex, rowData, changes) {
                    var c = $.extend({ Passwords: 0, Level: -1 }, changes);
                    if (c.Passwords == 0 && c.Level == -1)
                        return;
                    DarkCRM.Admin.Update(rowData);
                }
            });
        });

        var production = {
            del: function (id) {
                if (confirm("确定要删除吗?")) {
                    DarkCRM.Production.Delete(id, { success: function () {
                        $('#grid').datagrid("reload");
                    }
                    });
                }
            },
            edit: function (id) { parent.OpenTab({ title: "编辑:" + id, id: id, url: "editproduction.aspx?pid=" + id }); }
        };
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div id="grid">
    </div>
</asp:Content>